// 预处理返回的数据，防止后台服务不在线时，返回不合法数据
// const websiteUrl = 'http://192.168.1.55/api';
// const websiteUrl = 'http://spdb.mupengst.com/api';
// const imgUrl = 'http://spdb.mupengst.com/';
// const websiteUrl = 'http://m6mc.com/api';
// const imgUrl = 'http://m6mc.com/';
// const websiteUrl = 'http://vod.test/api';
const websiteUrl = 'http://jiyouzhibo.com/api';
const imgUrl = 'http://jiyouzhibo.com/';
 
	 function preHandleResult(res) {
		 // if (res.errMsg.trim() != "request:ok") {
			// showTip.showSuccessTip("后台服务不在线...", 2500);
		  //}
		 // success: (res) => {
			 // console.log(1);
		 // }
	 }
	 // 请求末尾加token
	 function appendToken (url) {
		 if (url.indexOf("?") == -1) {
		 		url += "?"
		 	} else {
		 		url += "&"
		 	}
		 	url += "access_token=" + accesstoken;
		 	return url;
	 } 
 
	 // appendToken(url) 
	 function request_get (url, param, header,successCallback, failCallback) {
		var _this = this;
		uni.request({
		    url: url, 
		    data: param,
			dataType: 'json',
			header: header,
			method: 'GET',
		    success: (res) => {
				preHandleResult(res);
				if(successCallback){
					 successCallback(res);
				}
		    },
			fail: (res) => {
				preHandleResult(res);
				if(failCallback){
					 failCallback(res);
				}
			}
		});
	 }
	
	 function request_post (url, param,header, successCallback, failCallback) {
		var _this = this;
		uni.request({
		    url: url, 
		    data: param,
			dataType: 'json',
			method: 'POST',
		    header: header,
		    success: (res) => {
				preHandleResult(res);
				if(successCallback){
					 successCallback(res);
				}
		    },
			fail: (res) => {
				preHandleResult(res);
				if(failCallback){
					 failCallback(res);
				}
			}
		});
	 }

	 // 获取手机号
	  function request_mobile (param,successCallback, failCallback) {
	 		var _this = this;
	 		uni.request({
	 		    url: websiteUrl+'/auth/captcha', 
	 		    data: param,
	 			dataType: 'json',
	 			method: 'POST',
	 		    success: (res) => {
	 				preHandleResult(res);
	 				if(successCallback){
	 					 successCallback(res);
	 				}
	 		    },
	 			fail: (res) => {
	 				preHandleResult(res);
	 				if(failCallback){
	 					 failCallback(res);
	 				}
	 			}
	 		});
	 	 }
	//校验邮箱格式
	function checkEmail(email){
		return RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/).test(email);
	}
	
	//校验手机格式
	function checkMobile(mobile){
		return RegExp(/^1[345789]\d{9}$/).test(mobile);
	}
	//校验身份证号码格式
	function checkIDcard(IDcard){
		return RegExp(/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/).test(IDcard);
	}
	//校验姓名格式
	function checkuserNm(userNm){
		return RegExp(/^(?:[\u4e00-\u9fa5]+)(?:·[\u4e00-\u9fa5]+)*$|^[a-zA-Z0-9]+\s?[\.·\-()a-zA-Z]*[a-zA-Z]+$/).test(userNm);
	}
	function pwd_reg(ni){
		return RegExp(/^.{6,18}$/).test(ni);
	}
	function pwd_num(ni){
		return RegExp(/[^\D]/g,'').test(ni);
	}
	//空白字符
	function kongbai(ni){
		// return RegExp(/^\s+|\s+$/g, "").test(ni);
		return RegExp(/^(\w){6,18}$/).test(ni);
	}
	function abc_num(num){
		return RegExp(/^[A-Za-z0-9]+$/).test(num);
	}

	
	function shou(smg){
		uni.showToast({
		    title: smg,
		    duration: 1000,
			icon:'none'
		});
	}
	 // 上面就是异步请求get/post/put/delete的封装了，到时候你直接导入正确传入参数就可以用这里的异步请求方法了。
	 // 当然需要先导出去，你才能导入其他地方引用。下面这就是导出。
	 // 你调用的时候是调 url_Request_get(url,param,success,fail) 方法。而不是function request_get(url,param,success,fail);
	 // 既然都导出去了，那我们就去别的地方引用去。
	export default {
			url_Request_get: function (url, param, success, fail) {
				return request_get (url, param, success, fail);
			},
			url_Request_post: function (url, param, success, fail) {
				return request_post (url,param,success,fail);
			},
			url_Request_put: function (url, param, success, fail) {
				return request_put (url,param,success,fail);
			},
			url_Request_delete: function (url, param, success, fail) {
				return request_delete (url,param,success,fail);
			},
			checkEmail:function (email){
				return checkEmail(email)
			},
			checkMobile:function (mobile){
				return checkMobile(mobile)
			},
			checkIDcard:function (IDcard){
				return checkIDcard(IDcard)
			},
			checkuserNm:function (userNm){
				return checkuserNm(userNm)
			},
			shou:function (userNm){
				return shou(userNm)
			},
			kongbai:function(ni){
				return kongbai(ni)
			},
			request_mobile:function (param,success, fail){
				return request_mobile(param,success, fail)
			},pwd_reg:function (param,success, fail){
				return pwd_reg(param,success, fail)
			},pwd_num:function (){
				return pwd_num(ni)
			},
			websiteUrl: websiteUrl,
			imgUrl:imgUrl,
			abc_num:function(num){
				return abc_num(num)
			}
		}
		